#include "Point.h"
#include "Polygon.h"
#include <iostream>

using std::cout;
using std::endl;
using std::vector;
Polygon::Polygon() {
	type = string("Default Polygon Type");
}

Polygon::Polygon(Polygon const &other){
	type = other.type;
	for(unsigned i=0; i<other._points.size();i++){
		Point* tPoint = other._points[i];
		this->_points.push_back(tPoint);
	}
}
Polygon::~Polygon() {
	vector<Point*>::iterator iter = _points.begin();
	cout << "DELETING POLYGON: BEGIN" << endl;
	while (iter != _points.end()) {
		cout << "  deleting point: ";
		cout<<(*iter)->getX()<<" ";
		cout<<(*iter)->getY()<<" ";
		cout << endl;
		delete (*iter);
		iter++;
	}
	cout << "DELETING POLYGON: END" << endl;
}

void Polygon::addPoint(Point* p) {
	Point* newp = new Point; //create a copy of the original pt
	newp->setX(p->getX());
	newp->setY(p->getY());
	_points.push_back(newp);
}

Point* Polygon::getPoint(int index) {
	return _points.at(index);
}

int Polygon::getNumOfPoints() {
	return _points.size();
}

void Polygon::copyPolygon(const Polygon & other){
	for (unsigned i=0;i<other._points.size();i++){
		this->_points[i] = other._points[i];
	}
}

void Polygon::print(){
	if (this->_points.size()>0){
		cout <<"Polygon:\n\tPoint 0)";
		this->_points[0]->print();
		for (unsigned i=1;i<this->_points.size();i++){
			cout <<"\n\tPoint "<<i<<")";
			this->_points[i]->print();
		}
		cout << endl;
	}
}
Polygon & Polygon::operator = (const Polygon & other){
	this->copyPolygon(other);
	return *this;
}

